package com.yr.ryjk.department;

import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.yr.ryjk.common.ErrorType;
import com.yr.ryjk.department.entity.Department;
import com.yr.ryjk.department.service.IDepartmentService;
import com.yr.ryjk.interceptor.authority.For;
import com.yr.ryjk.interceptor.authority.UserType;
import com.yr.ryjk.util.JSONUtil;

/**
 * 科室,部门
 * @author Rick
 *
 */
@Controller
@RequestMapping("/department")
public class DepartmentController {
	@Autowired
	private IDepartmentService departmentService;
	
	/**
	 * 获取指定科室的详细信息
	 * @param id
	 * @return
	 */
	@For(user={UserType.WEBSERVER_USER,UserType.APP_USER})
	@RequestMapping(value="/get",method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> getDepartmentInfo(String id){
		return JSONUtil.getJSON(ErrorType.SUCCESS,departmentService.getDepartmentById(id));		
	}
	

	/**
	 * 获取所有科室
	 * @return
	 */
	@RequestMapping("/all")
	@ResponseBody
	public Map<String, Object> getAllDepartment() {
		List<Department> list=departmentService.getAllDepartment();
		return JSONUtil.getJSON(ErrorType.SUCCESS,list);
	}
	
	
	/**
	 * 后台页面分页获取数据接口
	 * @param pageNo
	 * @param pageSize
	 * @param name 查询条件
	 * @param treatDisease 查询条件
	 * @return
	 */
	@For(user=UserType.WEBSERVER_USER)
	@RequestMapping(value="/list",method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> list(@RequestParam(value="pageNo",defaultValue="1") int pageNo,
			@RequestParam(value="pageSize",defaultValue="10") int pageSize,
			String name, String treatDisease){
		return JSONUtil.getJSON(ErrorType.SUCCESS,departmentService.getListOfPage(pageNo,pageSize,name,treatDisease));
	}
	
	/**
	 * APP页面获取数据接口
	 * @param name 查询条件
	 * @param treatDisease 查询条件
	 * @return
	 */
	@RequestMapping(value="/getList",method=RequestMethod.GET)
	@ResponseBody
	public Map<String, Object> getList(String name, String treatDisease){
		return JSONUtil.getJSON(ErrorType.SUCCESS,departmentService.getListOfApp(name,treatDisease));
	}
	
	/**
	 * 新增科室
	 * @param department
	 */
	@For(user=UserType.WEBSERVER_USER)
	@RequestMapping(value="/add",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> addDepartment(Department department){		
	     departmentService.addDepartment(department);
		 return JSONUtil.getJSON(ErrorType.SUCCESS);		 
	}
	
	/**
	 * 修改科室
	 * @param department
	 */
	@For(user=UserType.WEBSERVER_USER)
	@RequestMapping(value="/modify",method=RequestMethod.POST)
	@ResponseBody
	public Map<String, Object> modifyDepartment(Department department){		
	     departmentService.modifyDepartmentInfo(department);
		 return JSONUtil.getJSON(ErrorType.SUCCESS);		 
	}
}
